package com.itcast.mallapplet.controller.user;


import com.itcast.admin.vo.OrderAllVO;
import com.itcast.applet.dto.DityPageRequest;
import com.itcast.applet.dto.OrderDTO;
import com.itcast.applet.vo.OrderVO;
import com.itcast.mallapplet.service.OrderService;
import com.itcast.result.PageResult;
import com.itcast.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController()
@RequestMapping("/user/order")
@Slf4j
@Api(tags = "用户端-订单管理")
public class OrderController {

    @Autowired
    private OrderService orderService;

    @PostMapping("/add")
    @ApiOperation("新增订单")
    public Result orderAdd(@RequestBody OrderDTO orderDTO) {
        log.info("新增订单信息为{}",orderDTO);
        orderService.orderAdd(orderDTO);
        return Result.success();
    }

    @GetMapping("/query")
    @ApiOperation("查询单个订单")
    public Result<OrderVO> orderQuery(Long id) {
        log.info("查询单个订单的id为{}",id);
        OrderVO orderVO = orderService.orderQuery(id);
        return Result.success(orderVO);
    }

    @GetMapping("/queryAll")
    @ApiOperation("查询全部订单")
    public Result<List<OrderAllVO>> orderQueryAll() {
        //查询全部订单 List<Order> 使用增强for去遍历
        List<OrderAllVO> orderAllVOS = orderService.orderQueryAll();
        return Result.success(orderAllVOS);
    }

    @PostMapping("/refund")
    @ApiOperation("订单退款")
    public Result orderRefund(@RequestParam Long id) {
        log.info("退款订单id为{}",id);
        orderService.orderRefund(id);
        return Result.success();
    }










}
